<template>
	<view>
		<u-navbar placeholder fixed autoBack border title="工人信息采集"></u-navbar>
		<view class="d-p-30">
			<view class="d-font-24 d-flex d-row-center" style="color: #ADB4BD;">
				<u--image src="/static/icon/icon-55.png" width="30rpx" height="30rpx"></u--image>
				<text class="d-m-l-10">请将采集信息输入下方框中</text>
			</view>

			<view class="d-font-32 d-m-t-30" style="font-weight: bold;color: #151C24;">实名制信息</view>
			<view class="d-m-t-10">
				<view class="d-flex u-border-bottom" style="height: 80rpx;">
					<view class="d-font-28 d-m-r-30" style="color: #5D6672;"><text style="color: red;">*</text>人员姓名</view>
					<view class="d-flex-1"><u--input border="none" v-model="form.xm" inputAlign="right" placeholder="请输入" disabled disabledColor="#fff"></u--input></view>
				</view>
				<view class="d-flex u-border-bottom" style="height: 80rpx;">
					<view class="d-font-28 d-m-r-30" style="color: #5D6672;"><text style="color: red;">*</text>公民身份号码</view>
					<view class="d-flex-1"><u--input border="none" v-model="form.zjhm" inputAlign="right" placeholder="请输入" disabled disabledColor="#fff"></u--input></view>
				</view>
				<view class="d-flex u-border-bottom" style="height: 80rpx;">
					<view class="d-font-28 d-m-r-30" style="color: #5D6672;"><text style="color: red;">*</text>出生日期</view>
					<view class="d-flex-1"><u--input border="none" v-model="form.csrq" inputAlign="right" placeholder="请输入" disabled disabledColor="#fff"></u--input></view>
				</view>
				<view class="d-flex u-border-bottom" style="height: 80rpx;">
					<view class="d-font-28 d-m-r-30" style="color: #5D6672;"><text style="color: red;">*</text>性别</view>
					<view class="d-flex-1"><u--input border="none" v-model="form.xb_label" inputAlign="right" placeholder="请选择" disabled disabledColor="#fff"></u--input></view>
					<u-icon name="arrow-down" color="#8E9291" size="28rpx"></u-icon>
				</view>
				<view class="d-flex u-border-bottom" style="height: 80rpx;">
					<view class="d-font-28 d-m-r-30" style="color: #5D6672;"><text style="color: red;">*</text>民族</view>
					<view class="d-flex-1"><u--input border="none" v-model="form.mz_label" inputAlign="right" placeholder="请选择" disabled disabledColor="#fff"></u--input></view>
					<u-icon name="arrow-down" color="#8E9291" size="28rpx"></u-icon>
				</view>
				<view class="d-flex u-border-bottom" style="height: 80rpx;">
					<view class="d-font-28 d-m-r-30" style="color: #5D6672;">籍贯</view>
					<view class="d-flex-1"><u--input border="none" v-model="form.jiGuan" inputAlign="right" placeholder="请输入"></u--input></view>
				</view>
				<view class="d-flex u-border-bottom" style="height: 80rpx;">
					<view class="d-font-28 d-m-r-30" style="color: #5D6672;"><text style="color: red;">*</text>住址</view>
					<view class="d-flex-1"><u--input border="none" v-model="form.hjszd" inputAlign="right" placeholder="请输入"></u--input></view>
				</view>
				<view class="d-flex u-border-bottom" style="height: 80rpx;">
					<view class="d-font-28 d-m-r-30" style="color: #5D6672;"><text style="color: red;">*</text>签发机关</view>
					<view class="d-flex-1"><u--input border="none" v-model="form.qfjg" inputAlign="right" placeholder="请输入" disabled disabledColor="#fff"></u--input></view>
				</view>
				<view class="d-flex u-border-bottom" style="height: 80rpx;">
					<view class="d-font-28 d-m-r-30" style="color: #5D6672;"><text style="color: red;">*</text>有效期限开始</view>
					<view class="d-flex-1"><u--input border="none" v-model="form.yxksrq" inputAlign="right" placeholder="请输入" disabled disabledColor="#fff"></u--input></view>
				</view>
				<view class="d-flex u-border-bottom" style="height: 80rpx;">
					<view class="d-font-28 d-m-r-30" style="color: #5D6672;"><text style="color: red;">*</text>有效期限结束</view>
					<view class="d-flex-1"><u--input border="none" v-model="form.yxjsrq" inputAlign="right" placeholder="请输入" disabled disabledColor="#fff"></u--input></view>
				</view>
				<view class="d-flex u-border-bottom" style="height: 80rpx;">
					<view class="d-font-28 d-m-r-30" style="color: #5D6672;"><text style="color: red;">*</text>手机号码</view>
					<view class="d-flex-1"><u--input border="none" v-model="form.lxfs" type="number" maxlength="11" inputAlign="right" placeholder="请输入"></u--input></view>
				</view>
			</view>
			<view class="d-p-80">
				<view class="d-flex d-row-center">
					<view style="width: 450rpx;"><u-button text="上一步" shape="circle" type="info" @click="back"></u-button></view>
				</view>
				<view class="d-flex d-row-center d-m-t-30">
					<view style="width: 450rpx;"><u-button text="下一步" shape="circle" type="primary" @click="addRealName3"></u-button></view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { getRyxxByZjhm, getDict } from '../../../common/api.js';
export default {
	data() {
		return {
			form: {
				xm: '', // 人员姓名:xm（根据扫描身份证获取）【必填】
				zjhm: '', // 证件号码:zjhm（根据扫描身份证获取）【必填】
				csrq: '', // 出生日期:csrq（根据扫描身份证获取）【必填】
				xb: '', // 性别【字典=xb】:xb（根据身份证件号码计算获取，可以修改）【必填】-- 提交时 转
				mz: '', // 民族【字典=mz】:mz（默认值：汉族）【必填】 -- 提交时 转
				jiguan: '', // 籍贯:jiguan
				hjszd: '', // 住址：hjszd【必填】
				qfjg: '', // 签发机关：qfjg（根据扫描身份证获取）
				yxksrq: '', // 有效期限开始：yxksrq（根据扫描身份证获取）
				yxjsrq: '', // 有效期限结束:yxjsrq（根据扫描身份证获取）
				lxfs: '' // 手机号码：lxfs【必填】
			},
			dict: {
				xb: [],
				mz: []
			}
		};
	},
	onLoad() {
		getDict({ name: 'xb' }).then(e => {
			this.dict.xb = e.data.map(item => {
				return { value: item.dictValue, name: item.dictLabel };
			});
			this.isVery();
		});
		getDict({ name: 'mz' }).then(e => {
			this.dict.mz = e.data.map(item => {
				return { value: item.dictValue, name: item.dictLabel };
			});
			this.isVery();
		});
	},
	onShow() {
		let form = uni.getStorageSync('store_form') || {};
		
		this.form = uni.$u.deepMerge(this.form,form);
		this.isVery();
		// 根据证件号码查询基本信息 -- 新增的时候查询
		// if (this.form.zjhm && !this.form.id) {
		// 	getRyxxByZjhm({
		// 		zjhm: this.form.zjhm
		// 	}).then(e => {
		// 		if (e.code == 200) {
		// 			let data = e.root || {};
		// 			this.form = {
		// 				...this.form,
		// 				...data
		// 			};
		// 		}
		// 	});
		// }
	},
	methods: {
		isVery() {
			// 处理转义
			if (!uni.$u.test.digits(this.form.xb)) {
				this.form.xb_label = this.form.xb;
				for (let i in this.dict.xb) {
					if (this.dict.xb[i].name == this.form.xb) {
						this.form.xb = this.dict.xb[i].value;
						break;
					}
				}
			} else {
				for (let i in this.dict.xb) {
					if (this.dict.xb[i].value == this.form.xb) {
						this.form.xb_label = this.dict.xb[i].name;
						break;
					}
				}
			}
			if (!uni.$u.test.digits(this.form.mz)) {
				this.form.mz_label = this.form.mz;
				for (let i in this.dict.mz) {
					if (this.dict.mz[i].name == this.form.mz) {
						this.form.mz = this.dict.mz[i].value;
						break;
					}
				}
			} else {
				for (let i in this.dict.mz) {
					if (this.dict.mz[i].value == this.form.mz) {
						this.form.mz_label = this.dict.mz[i].name;
						break;
					}
				}
			}
			this.$forceUpdate();
		},
		back() {
			uni.$u.route({
				type: 'back'
			});
		},
		addRealName3() {
			// 要做验证
			if (!this.form.hjszd) {
				return uni.$u.toast('请输入住址');
			}
			if (!this.form.lxfs) {
				return uni.$u.toast('请输入手机号码');
			}
			if (!uni.$u.test.mobile(this.form.lxfs)) {
				return uni.$u.toast('请输入正确的手机号码');
			}
			this.isVery();
			uni.setStorageSync('store_form', this.form);
			uni.$u.route({
				url: '/pages/index/member/addRealName3'
			});
		}
	}
};
</script>

<style lang="scss"></style>
